﻿using System;
using System.Data;
using MySql.Data.MySqlClient;


namespace ik.DB.MySQL
{
    public class clDbMySQL : clDB
    {
        #region "ToString"
        /// <summary>
        /// class information
        /// </summary>
        /// <returns>String</returns>
        public override String ToString()
        {
            return "Class name: ik.DB.MySQL \n\n" +
                   "Class version: " + Environment.Version.ToString() + "\n" +
                   "OS version: " + Environment.OSVersion.ToString() + "\n" +
                   "Computer name: " + Environment.MachineName + "\n" +
                   "Rights: (c) 2011 - by Ivan Kruger";
        }
        #endregion

        /// <summary>
        /// contrutor
        /// </summary>
        public clDbMySQL()
            : base(enSGBD.MySql)
        {
        }

        #region "GetCnn"
        /// <summary>
        /// conecta ao banco de dados MySql
        /// </summary>
        /// <param name="server">nome do servidor</param>
        /// <param name="porta">porta de acesso</param>
        /// <param name="database">nome do banco de dados</param>
        /// <param name="user">usuário</param>
        /// <param name="pwd">senha</param>
        public void GetCnn(String user, String pwd, String server, String database, Int32 porta)
        {
            try
            {
                cnnString = String.Format("Server={0};Port={1};Database={2};Uid={3};Pwd={4};",
                                server, porta.ToString(), database, user, ik.FunctionsDB.clFunctionsDB.CrypTo2(pwd, FunctionsDB.enEncryption.Descriptar));

                if (cnnDB == null)
                    cnnDB = new MySqlConnection(cnnString);
                if (cnnDB.State != ConnectionState.Open)
                    cnnDB.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }

}

